package com.itheima.day16反射机制与类加载.反射核心案例_使用场景;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

public class 类加载加反射机制案例二 {
    public static void main(String[] args) throws Exception {
        ClassLoader loader = 类加载加反射机制案例二.class.getClassLoader();
        InputStream input = loader.getResourceAsStream("prop.properties");
        Properties prop=new Properties();
        prop.load(input);
        Class<?> clazz = Class.forName(prop.getProperty("className"));
        Constructor con = clazz.getConstructor();
        con.setAccessible(true);
        Object obj = con.newInstance();
        Method method = clazz.getDeclaredMethod(prop.getProperty("method"));
        method.setAccessible(true);
        Object invoke = method.invoke(obj);
        if (invoke!=null){
            System.out.println(invoke);
        }
    }
}
